/*
 *  Arrow
 *
 *  Created by David Giovannini on 1/5/07.
 *  Copyright 2007 Software by Jove. All rights reserved.
 *
 */
 
#ifndef SBJ_Arrow_SynchronousMsg_h
#define SBJ_Arrow_SynchronousMsg_h

#include "SBJ/Arrow/Message.h"
#include "SBJ/Thread/Blocker.h"

#include <string>

namespace SBJ
{

namespace Arrow
{

class SynchronousMsg : public Message
{
public:
	enum { fully_independent = true };

	/// Parameterized constructor, requires a topic
	SynchronousMsg( const Topic& topic, Priority priority = highest_priority )
	: Message( topic, priority )
	{
	}

	/// Copy Constructor
	SynchronousMsg( SynchronousMsg& rhs )
	: Message( rhs )
	, m_blocker( rhs.m_blocker )
	{
	}

	/// Destructor
	virtual ~SynchronousMsg( void )
	{
	}

	/// Call to block until Message has been executed or fully dispatched
	void wait( void )
	{
		m_blocker.wait();
	}

	/// 
	// Overrides must call SynchronousMsg::dropped
	virtual void dropped( EDropped reason )
	{
		m_blocker.finish();
	}

	/// Override for Message execution when the Message has an empty Topic
	// Overrides must call SynchronousMsg::execute
	virtual void execute( void )
	{
		m_blocker.finish();
	}

	/// Called at the completion of dispatching
	// Overrides must call SynchronousMsg::endInvocations
	virtual void endInvocations( void )
	{
		m_blocker.finish();
	}

private:
	Blocker m_blocker;
};

}

}

#endif